;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Stock.UnusualIn", [])
        .controller("UnusualInCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "$timeout", "EventBus", "$filter", "UserContextService","$stateParams", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, $timeout, EventBus, $filter, UserContextService,$stateParams) {
            $scope.activeFlag = [true, false, false, false, false];
            $scope.datePickerFlag = [false, false];
            $scope.markInfo = {
                allCheckedBill: false,
                allCheckedMaterial: false,
                curRow: -1
            };
            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };
            $scope.submitted = false;
            $scope.condition = {};
            $scope.toolbarConfig = {
                showAdvanceSearch: false,
                showColConfig: false,
                showMateriel: false
            };
            $scope.dataList = [];
            $scope.tbConf = {
                fixedWidth:220,
                scrollWidth: 1620,
                tableCol: [
                    {
                        type: "",
                        name: "其它入库单号",
                        dataField: "abnormalNo",
                        width: 180,
                        isShow: true,
                        isFixed: false,
                        clickFn: "viewDetail",
                    },
                    {
                        type: "",
                        name: "入库原因",
                        dataField: "type",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "",
                        name: "调入仓库",
                        dataField: "inLocation",
                        width: 130,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "",
                        name: "入库状态",
                        dataField: "stateShow",
                        width: 110,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "",
                        name: "制单人",
                        dataField: "createName",
                        width: 120,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "",
                        name: "制单时间",
                        dataField: "applicationDateShow",
                        width: 140,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "",
                        name: "备注",
                        dataField: "note",
                        width: 200,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "operate",
                        name: "操作",
                        dataField: "",
                        width: 180,
                        isShow: true,
                        isFixed: true,
                    }
                ]
            };
            $scope.newTbConf = {
                scrollWidth: 1000,
                tableCol: [
                    {
                        name: "零件编号",
                        width: 150,
                        dataField: "materialsNo",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "零件简号",
                        width: 120,
                        dataField: "materialsShortNo",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "零件中文名",
                        width: 200,
                        dataField: "materialsDes",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "零件英文名",
                        width: 150,
                        dataField: "materialsDesEn",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "入库数量",
                        width: 150,
                        dataField: "qty",
                        input: true,
                        inputType: "txt"
                    },
                    {
                        name: "单位",
                        width: 120,
                        dataField: "unit",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "零件所属车型",
                        width: 140,
                        dataField: "modelCode",
                        input: false,
                        inputType: ""
                    },
                ]
            };
            $scope.editTbConf = {
                scrollWidth: 980,
                tableCol: [
                    {
                        name: "零件编号",
                        width: 150,
                        dataField: "materialsNo",
                        input: false,
                        inputType: "",
                        isShow: true
                    },
                    {
                        name: "零件中文名",
                        width: 200,
                        dataField: "materialsDes",
                        input: false,
                        inputType: "",
                        isShow: true
                    },
                    {
                        name: "单位",
                        width: 120,
                        dataField: "unit",
                        input: false,
                        inputType: "",
                        isShow: true
                    },
                    {
                        name: "入库数量",
                        width: 150,
                        dataField: "qty",
                        input: true,
                        inputType: "txt",
                        isShow: true
                    },
                    {
                        name: "实际入库数量",
                        width: 160,
                        dataField: "realQty",
                        input: false,
                        inputType: "",
                        isShow: true
                    },
                    {
                        name: "入库状态",
                        width: 150,
                        dataField: "stateShow",
                        input: false,
                        inputType: "",
                        isShow: true
                    },
                ]
            };
            $scope.viewTbConf = {
                scrollWidth: 930,
                tableCol: [
                    {
                        type: "",
                        name: "序号",
                        dataField: "rownum",
                        width: 80,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        name: "零件编号",
                        width: 150,
                        dataField: "materialsNo",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "零件中文名",
                        width: 200,
                        dataField: "materialsDes",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "单位",
                        width: 100,
                        dataField: "unit",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "入库数量",
                        width: 110,
                        dataField: "qty",
                        input: true,
                        inputType: "txt"
                    },
                    {
                        name: "实际入库数量",
                        width: 160,
                        dataField: "realQty",
                        input: true,
                        inputType: "txt",
                        isShow: false
                    },
                    {
                        name: "入库状态",
                        width: 130,
                        dataField: "stateShow",
                        input: true,
                        inputType: "txt",
                        isShow: false
                    },
                ]
            };
            $scope.inTbConf = {
                scrollWidth: 900,
                tableCol: [
                    {
                        name: "零件编号",
                        width: 150,
                        dataField: "materialsNo",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "零件中文名",
                        width: 200,
                        dataField: "materialsDes",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "分类",
                        width: 100,
                        dataField: "materialsType",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "单位",
                        width: 100,
                        dataField: "unit",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "入库数量",
                        width: 110,
                        dataField: "qty",
                        input: false,
                        inputType: ""
                    },
                    {
                        name: "储位",
                        width: 260,
                        dataField: "locationCode",
                        input: true,
                        inputType: "func"
                    },
                    {
                        name: "入库状态",
                        width: 130,
                        dataField: "stateShow",
                        input: false,
                        inputType: "",
                        isShow: false
                    }
                ]
            };
            $scope.orderObj = {
                headerInfo: {},
                detailList: []
            };
            $scope.exportParam = {
                sectionUrl: ybHttp.RequestUrl("device", "/abnormalIn/export"),
                sectionParam: {ids: []},
                allUrl: ybHttp.RequestUrl("dReport", "/abnormalIn/exportAll")
            };
            $scope.inTypeList = [];
            $scope.inState = [
                {id: 0, name: "未入库"},
                {id: 1, name: "部分入库"},
                {id: 2, name: "已入库"},
                {id: 3, name: "强制结单"}
            ];
            $scope.tabFlag = {};

            var btnPermissionCode = {
                unusualInAdd: window.ActionCode.unusualInAdd,
                unusualInEdit: window.ActionCode.unusualInEdit,
                unusualInDel: window.ActionCode.unusualInDel,
                unusualInPrint: window.ActionCode.unusualInPrint,
                unusualInIn: window.ActionCode.unusualInIn,
                unusualInExport: window.ActionCode.unusualInExport,
                unusualInObligateAdd: window.ActionCode.unusualInObligateAdd,
                unusualInObligatePosting: window.ActionCode.unusualInObligatePosting,
                mandatoryFinish: window.ActionCode.unusualInMandatoryFinish,
                unusualInSyncMes: window.ActionCode.unusualInSyncMes,
                unusualInAudit: window.ActionCode.unusualInAudit,
            };

            $scope.btnPermission = {
                unusualInAdd: true,
                unusualInEdit: true,
                unusualInDel: true,
                unusualInPrint: true,
                unusualInIn: true,
                unusualInExport: true,
                unusualInObligateAdd: true,
                unusualInObligatePosting: true,
                mandatoryFinish:　true,
                unusualInSyncMes: true,
                unusualInAudit: true,
            };

            function setBtnPermission() {
                for (var key in btnPermissionCode) {
                    $scope.btnPermission[key] = UserContextService.CheckPermission([btnPermissionCode[key]]);
                }
            }

            $scope.setFixedWidth = function () {
                $scope.tbStyle = {
                    fixedWidth: {left: $scope.tbConf.fixedWidth + "px"}
                };
            };

            $scope.changeTab = function (index) {
                $scope.activeFlag = [false, false, false, false, false];
                $scope.activeFlag[index] = true;
                $scope.submitted = false;
                switch (index) {
                    case 0:
                        initData();
                        break;
                    case 1:
                        if ($scope.inTypeList.length === 0) {
                            getTypeList();
                        }
                        break;
                    case 2:
                        break;
                    case 3:
                        break;
                    default:
                        break;
                }
            };

            function initData() {
                $scope.orderObj = {
                    headerInfo: {},
                    detailList: []
                };
                $scope.tabFlag = {};
                $scope.markInfo.allCheckedMaterial = false;
                $scope.toolbarConfig.showMateriel = false;
            }

            function getDataList(curPage) {
                $scope.markInfo = {
                    allCheckedBill: false,
                    allCheckedMaterial: false,
                    curRow: -1
                };
                $scope.exportParam.sectionParam.ids = [];
                var service = "device";
                var reqUrl = "/abnormalIn/list";
                var param = {};
                param.pageSize = $scope.pageInfo.pageSize;
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }
                param.pageNum = $scope.pageInfo.curPage;
                param.filters = angular.copy($scope.condition);
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.isChecked = false;
                        item.applicationDateShow = $filter("YbDate")(item.applicationDate,"yyyy-MM-dd HH:mm:ss");
                        item.stateShow = $filter("ProgressStatus")(item.state, "inDepot");
                    });
                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                });
            }

            $scope.selectRow = function (index) {
                $scope.markInfo.curRow = index
            };

            $scope.tdClick = function (item, fnType) {
                switch (fnType) {
                    case "viewDetail":
                        viewDetail(item);
                        break;
                    default:
                        break;
                }
            };

            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig["show" + toolbar] = true;
                    });
                }
            };

            $scope.switchDataPicker = function (index) {
                $scope.datePickerFlag = [false, false];
                if (angular.isDefined(index)) {
                    $scope.datePickerFlag[index] = true;
                }
            };

            $scope.checkDate = function (obj, startFiled, endFiled) {
                var timeFormatObj = ybWidget.CheckDate(obj[startFiled], obj[endFiled]);
                if (!!timeFormatObj.tStart) {
                    obj[startFiled] = timeFormatObj.tStart;
                }
                if (!!timeFormatObj.tEnd) {
                    obj[endFiled] = timeFormatObj.tEnd;
                }
            };

            $scope.search = function (curpage) {
                getDataList(curpage);
            };

            $scope.reset = function () {
                $scope.condition = {};
            };

            function getBillIds() {
                $scope.exportParam.sectionParam.ids = [];
                angular.forEach($scope.dataList, function (item) {
                    if (!!item.isChecked) {
                        $scope.exportParam.sectionParam.ids.push(item.id);
                    }
                });
            }

            $scope.selectSingle = function (item, list, type) {
                if (!item.isChecked) {
                    $scope.markInfo["allChecked" + type] = false;
                } else {
                    if (!checkAll(list)) {
                        $scope.markInfo["allChecked" + type] = false;
                    } else {
                        $scope.markInfo["allChecked" + type] = true;
                    }
                }
                getBillIds();
            };

            function checkAll(list) {
                var selectAll = false;
                for (var i = 0, len = list.length; i < len; i++) {
                    if (!list[i].isChecked) {
                        selectAll = false;
                        break;
                    }
                    selectAll = true;
                }
                return selectAll;
            }

            $scope.selectAll = function (list, type) {
                angular.forEach(list, function (item) {
                    item.isChecked = $scope.markInfo["allChecked" + type];
                });
                getBillIds();
            };

            $scope.applyIn = function () {
                $scope.tabFlag.type = 0;
                $scope.orderObj.headerInfo.deptId = $scope.curUser.deptId;
                $scope.orderObj.headerInfo.dept = $scope.curUser.deptName;
                $scope.orderObj.headerInfo.createId = $scope.curUser.userId;
                $scope.orderObj.headerInfo.createName = $scope.curUser.name;
                $scope.orderObj.headerInfo.applyDate = +new Date();
                $scope.changeTab(1);
            };

            function getTypeList() {
                var service = "device";
                var reqUrl = "/billTypeConfig/list";
                var param = {filters: {inOut: 0}, pageNum: 0, pageSize: 0};
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return false;
                    }
                    $scope.inTypeList = resp.value.list;
                })
            }

            $scope.delData = function (delType, billId) {
                var service = "device";
                var reqUrl = "/abnormalIn/remove";
                var billIds = [];

                if (delType === "single") {
                    billIds.push(billId);
                }

                if (delType === "batch") {
                    for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                        if (!!$scope.dataList[i].isChecked) {
                            billIds.push($scope.dataList[i].id);
                        }
                    }
                }

                if (billIds.length === 0) {
                    ybWidget.ShowMessage('请选择需要删除的行', MESG_TYPE.Error);
                    return;
                }
                ybWidget.ShowMessage("确定要删除吗？", MESG_TYPE.Ask).then(function () {
                    ybHttp.Post(service, reqUrl, billIds).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return;
                        }
                        ybWidget.ShowToaster('success', '操作成功');
                        getDataList();
                    });
                });
            };

            $scope.selectWarehouse = function () {
                ybWidget.WarehouseUsingSelector().then(function (data) {
                    if (!!$scope.orderObj.headerInfo.inLocation && (data.warehouseCode !== $scope.orderObj.headerInfo.inLocation)) {
                        $scope.orderObj.headerInfo.inArea = "";
                        $scope.orderObj.headerInfo.sapInArea = "";
                    }
                    $scope.orderObj.headerInfo.inLocation = data.warehouseCode;
                })
            };

            $scope.clearWarehouse = function () {
                $scope.orderObj.headerInfo.inLocation = "";
                $scope.orderObj.headerInfo.inArea = "";
                $scope.orderObj.headerInfo.sapInArea = "";
            };

            $scope.selectArea = function () {
                if (!$scope.orderObj.headerInfo.inLocation) {
                    ybWidget.ShowToaster('error', '请选择调入仓库');
                    return;
                }
                var param = {};
                param.warehouseCode = $scope.orderObj.headerInfo.inLocation;
                ybWidget.DepotAreaSelector(param).then(function (data) {
                    $scope.orderObj.headerInfo.inArea = data.areaCode;
                    $scope.orderObj.headerInfo.sapInArea = data.sapCode;
                })
            };

            $scope.clearArea = function () {
                $scope.orderObj.headerInfo.inArea = "";
                $scope.orderObj.headerInfo.sapInArea = "";
            };

            $scope.selMateriel = function (e) {
                if (!!$scope.toolbarConfig.showMateriel) {
                    e.stopPropagation();
                } else {
                    if (!$scope.orderObj.headerInfo.supplierOrgId) {
                        ybWidget.ShowToaster('error', '请选择供货商');
                        return;
                    }
                    $timeout(function () {
                        $scope.toolbarConfig.showMateriel = true;
                        EventBus.Publish("getMaterial", { supplierOrgId: $scope.orderObj.headerInfo.supplierOrgId });
                    });
                }
            };

            $scope.importMateriel = function () {
                if (!$scope.orderObj.headerInfo.supplierOrgId) {
                    ybWidget.ShowToaster('error', '请选择供货商');
                    return;
                }

                var param = {
                    name: "零件",
                    templateReqService: "device",
                    templateReqUrl: "/abnormalIn/download",
                    importReqService: "device",
                    importReqUrl: "/abnormalIn/import",
                    importErrorUrl: "",
                    otherParams: {
                        supplierOrgId: $scope.orderObj.headerInfo.supplierOrgId
                    }
                };
                ybWidget.ImportFile(param).then(function (data) {
                    angular.forEach(data, function (item) {
                        item.isChecked = false;
                    });
                    $scope.orderObj.detailList = [];
                    $scope.orderObj.detailList = angular.copy(data);
                });
            };

            $scope.delMateriel = function (item, index, e) {
                ybWidget.ShowMessage("确定要删除该记录吗？", MESG_TYPE.Ask).then(function () {
                    $scope.orderObj.detailList.splice(index, 1);
                    EventBus.Publish("setMaterial", item.materialsNo);
                    e.stopPropagation();
                });
            };

            $scope.batchDelMateriel = function () {
                var selectedCount = 0;
                for (var i = 0, len = $scope.orderObj.detailList.length; i < len; i++) {
                    if (!!$scope.orderObj.detailList[i].isChecked) {
                        selectedCount++;
                    }
                }
                if (!selectedCount) {
                    ybWidget.ShowMessage('请选择需要删除的行', MESG_TYPE.Error);
                    return;
                }
                ybWidget.ShowMessage("确定要删除选中的记录吗？", MESG_TYPE.Ask).then(function () {
                    for (var i = $scope.orderObj.detailList.length - 1; i >= 0; i--) {
                        if (!!$scope.orderObj.detailList[i].isChecked) {
                            $scope.orderObj.detailList.splice(i, 1);
                        }
                    }
                    if ($scope.orderObj.detailList.length === 0) {
                        $scope.markInfo.allCheckedMaterial = false;
                    }
                    EventBus.Publish("setMaterial");
                });
            };

            function getDetail(billId) {
                var service = "device";
                var reqUrl = "/abnormalIn/item";
                var param = {};
                param.id = billId;
                return ybHttp.Get(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return false;
                    }
                    angular.forEach(resp.value.detailList, function (item) {
                        item.stateShow = $filter("ProgressStatus")(item.state, "inDepot");
                    });
                    return resp.value;
                });
            }

            function viewDetail(item) {
                getDetail(item.id).then(function (data) {
                    if (!data) {
                        return;
                    }
                    $scope.changeTab(3);
                    $scope.orderObj = data;
                });
            }

            $scope.editData = function (item) {
                getDetail(item.id).then(function (data) {
                    if (!data) {
                        return;
                    }
                    $scope.tabFlag.type = 1;
                    $scope.changeTab(2);
                    $scope.orderObj = data;
                });
            };

            $scope.checkStock = function (item) {
                item.qtyErr = false;

                if (!item.qty || parseFloat(item.qty)<=0) {
                    item.qtyErr = true;
                    item.qtyErrMsg = "入库数量不能为空和0";
                    return;
                }
                if (parseFloat(item.qty) < parseFloat(item.realQty)) {
                    item.qtyErr = true;
                    item.qtyErrMsg = "入库数量不能小于实际入库数量";
                }
            };

            $scope.printBill = function (item) {
                var id = item.id;
                var billIds = [];
                billIds.push(id);
                var param = {
                    billId: billIds,
                    printType: "UnusualIn"
                };
                ybWidget.SetIsPrintOrPreview(param);
            };

            $scope.batchPrint = function () {
                var billIds = [];
                for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                    if (!!$scope.dataList[i].isChecked) {
                        billIds.push($scope.dataList[i].id);
                    }
                }
                if (billIds.length === 0) {
                    ybWidget.ShowMessage('请选择需要打印的行');
                    return;
                }

                var param = {
                    cusParam: { billIds },
                    cusInterface: '/abnormalIn/batchPrintInfo',
                    printType: "UnusualIn",
                    isBatchPrint: true,
                };
                ybWidget.SetIsPrintOrPreview(param).then(function() {
                    getDataList();
                });
            };

            function checkListValid() {
                var isValid = true;
                for (var i = 0, len = $scope.orderObj.detailList.length; i < len; i++) {
                    if (!$scope.orderObj.detailList[i].qty || parseFloat($scope.orderObj.detailList[i].qty)<=0) {
                        isValid = false;
                        $scope.orderObj.detailList[i].qtyErr = true;
                        $scope.orderObj.detailList[i].qtyErrMsg = "入库数量不能为空和0";
                        break;
                    }
                    if ($scope.tabFlag.type === 1 && (parseInt($scope.orderObj.detailList[i].qty) < parseInt($scope.orderObj.detailList[i].realQty))) {
                        isValid = false;
                        $scope.orderObj.detailList[i].qtyErr = true;
                        $scope.orderObj.detailList[i].qtyErrMsg = "入库数量不能小于实际入库数量";
                        break;
                    }
                }
                return isValid;
            }

            $scope.saveData = function (isValid) {
                if (angular.isDefined(isValid) && !isValid) {
                    $scope.submitted = true;
                    return;
                }
                if ($scope.orderObj.detailList.length === 0) {
                    ybWidget.ShowToaster('error', '零件不可为空');
                    return;
                }
                var listValid = checkListValid();
                if (!listValid) {
                    return;
                }
                var service = "device";
                var reqUrl = "/abnormalIn/add";
                if ($scope.tabFlag.type === 1) {
                    reqUrl = "/abnormalIn/update";
                }
                var param = angular.copy($scope.orderObj);
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    ybWidget.ShowToaster('success', '操作成功');
                    if ($scope.tabFlag.type === 0) {
                        getDataList(1);
                    } else {
                        getDataList();
                    }
                    $scope.changeTab(0);
                });
            };

            $scope.inbound = function (item) {
                getDetail(item.id).then(function (data) {
                    if (!data) {
                        return;
                    }
                    $scope.orderObj = data;
                    angular.forEach($scope.orderObj.detailList, function (item) {
                        item.stateShow = $filter("ProgressStatus")(item.state, "inDepot");
                    });
                    $scope.changeTab(4);
                });
            };

            $scope.selDepot = function (item) {
                var param = {
                    warehouseCode: $scope.orderObj.headerInfo.inLocation
                };
                ybWidget.DepotSelector(param).then(function (data) {
                    item.warehouseCode = data.warehouseCode;
                    item.areaCode = data.areaCode;
                    item.locationCode = data.locationCode;
                })
            };

            $scope.clearDepot = function (item) {
                item.warehouseCode = "";
                item.areaCode = "";
                item.locationCode = "";
            };

            $scope.mandatoryFinish = function (billNo, billId, materialsNo) {
                ybWidget.ShowMessage("确定要结单吗？", MESG_TYPE.Ask).then(function () {
                    var service = "device";
                    var reqUrl = "/abnormalIn/manualFinish";
                    var param = {
                        billNo: billNo,
                        materialsNo: materialsNo ? materialsNo : null
                    };
                    ybHttp.Post(service, reqUrl, param).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return;
                        }
                        ybWidget.ShowToaster('success', '操作成功');
                        if (!!billId) {
                            getDetail(billId).then(function (data) {
                                if (!data) {
                                    return;
                                }
                                $scope.orderObj = data;
                            });
                        }
                        getDataList();
                    });
                }, function () {
                });
            };

            $scope.inboundSubmit = function () {
                /* if (true) {
                    // 条码入库
                    UserContextService.BarcodeInbound($scope.orderObj.detailList, 'abnormalNo', 'qty', 'state').then(() => {
                        $scope.changeTab(0);
                        getDataList();
                    })
                    return;
                } */

                // 以非条码入库
                notBarcodeInbound();
            };

            // 非条码入库
            function notBarcodeInbound () {
                var service = "device";
                var reqUrl = "/warehouseInboundRecord/receive";
                var param = {
                    headerInfo: {},
                    detailList: []
                };
                var errorCount = 0;
                param.headerInfo.businessOrder = $scope.orderObj.headerInfo.abnormalNo;
                angular.forEach($scope.orderObj.detailList, function (item) {
                    var listRow = {};
                    listRow.materialNo = item.materialsNo;
                    listRow.warehouseCode = item.warehouseCode;
                    listRow.areaCode = item.areaCode;
                    listRow.locationCode = item.locationCode;
                    item.locationErr = false;
                    if((item.state === 0 || item.state === 1) && !item.locationCode){
                        item.locationErr = true;
                        errorCount++;
                    }
                    param.detailList.push(listRow);
                });
                if(errorCount> 0){
                    return;
                }
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    ybWidget.ShowToaster('success', '操作成功');
                    $scope.changeTab(0);
                    getDataList();
                });
            };

            $scope.cancel = function () {
                $scope.changeTab(0);
            };

            $scope.selectSold = function () {
                var param = {
                    name: "供货商",
                    type: "supplier",
                };
                ybWidget.SingleSelector(param).then(function (data) {
                    $scope.orderObj.headerInfo.supplierOrgId = data.platOrgId;
                    $scope.orderObj.headerInfo.supplierOrgName = data.companyName;
                    clearMateriel();
                })
            };

            $scope.clearSold = function () {
                $scope.orderObj.headerInfo.supplierOrgId = "";
                $scope.orderObj.headerInfo.supplierOrgName = "";
                clearMateriel();
            };

            function clearMateriel() {
                $scope.orderObj.detailList = [];
                $scope.markInfo.allCheckedMaterial = false;
                $timeout(function () {
                    EventBus.Publish("clearMaterial");
                });
            }

            (function () {
                getDataList();
                $scope.setFixedWidth();
                UserContextService.SetBtnPermission(setBtnPermission);
            })();
        }])
    ;
})(window, window.angular);
